<?php
namespace app\controllers;

use app\models\KuaidisendRecorder;

class KuaidisendController extends BaseController{
    //添加
    public function actionAdd(){
        $post = \Yii::$app->request->post();
        $id = $post['KuaidisendRecorder']['id'];
        if($id){
            $model = KuaidisendRecorder::find()->where('id=:id',[':id' => $id])->one();
            if(empty($model)){
                $result = ['result'=>0,'data'=>'不存在相关内容，请重新操作'];
                return json_encode($result);
            }
        }else{
            $model = new KuaidisendRecorder();
        }
        $result = $model->add($post);
        return json_encode($result);
    }

    //获取列表
    public function actionList(){
        $list = KuaidisendRecorder::find()->asArray()->all();
        $result = ['result'=>1,'data'=>$list];
        return json_encode($result);
    }

    //获取内容
    public function actionOne(){
        $id = \Yii::$app->request->post('id');
        $model = KuaidisendRecorder::find()->where('id=:id',[':id' => $id])->asArray()->one();
        if(empty($model)){
            $result = ['result'=>0,'data'=>'不存在相关内容，请重新操作'];
            return json_encode($result);
        }
        $result = ['result'=>1,'data'=>$model];
        return json_encode($result);
    }

    //删除内容
    public function actionDel(){
        $id = \Yii::$app->request->post('id');
        $model = KuaidisendRecorder::find()->where('id=:id',[':id' => $id])->one();
        if(!$model){
            $result = ['result'=>0,'data'=>'不存在相关内容，请重新操作'];
            return json_encode($result);
        }
        $model->delete();
        $result = ['result'=>1,'data'=>'操作成功'];
        return json_encode($result);
    }

}

